﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaseUI.Base;
using System.ComponentModel;
using System.Web;
using Utility;
using Utility.Model;

namespace BaseUI
{
    public class BaseHandler : HandlerBase_Class
    {
        /// <summary>
        /// 登录用户的账号
        /// </summary>
        public string Account { get; private set; }
        /// <summary>
        /// 用户的Sesson
        /// </summary>
        public UserSession UserInfo { get; private set; }

        /// <summary>
        /// 处理每个请求
        /// </summary>
        /// <param name="context"></param>
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override void ProcessRequest(HttpContext context)
        {
            this.Account = context.User.Identity.Name;
            if (this.Account.IsNullOrEmpty())
            {
                this.Account = UserSessionService.GetLoginName(base.Context);
            }
            if (this.Account.IsNullOrEmpty())
            {
                base.GetFailureJson("非法访问，没有登录用户");
            }
            else
            {
                this.UserInfo = UserSessionService.GetUserInfo(this.Account, base.IP);
                if (this.UserInfo == null)
                {
                    base.GetFailureJson("非法访问，没有登录用户");
                }
                else
                {
                    base.ProcessRequest_Instance();
                }
            }
        }
    }
}
